package controller.menubar.show;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.zip.CRC32;
import java.util.zip.CheckedInputStream;

import javax.swing.JOptionPane;

import model.GlobalParams;
import view.MainFrame;

public class CheckSumCreate implements ActionListener {
	
	public CheckSumCreate(MainFrame frame) {
		
		this.frame = frame;
	}
		
	@Override
	public void actionPerformed(ActionEvent arg0) {	
		
		
		File f =  frame.getMainPanel().getPrimary().getDiskContent().getSelectedFile();
		//System.out.println(f.getAbsolutePath());
		
		FileInputStream is = null;
		try {
			is = new FileInputStream(f);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		CheckedInputStream  s = new CheckedInputStream(is, new CRC32());
		
		BufferedInputStream bf = new BufferedInputStream(s);
		try {
			while (bf.read() != -1) {
				
				
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		//System.out.println(s.getChecksum());
		JOptionPane.showConfirmDialog(frame, s.getChecksum().getValue(), GlobalParams.getInstance().stringCollection.getOther_operation_manager(), JOptionPane.WARNING_MESSAGE);
         
	}
	private MainFrame frame;


}
